
package Server.ExtComponents.utilsKit.IDFactory;


import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class IdFactory
{

	protected boolean _initialized;
	
	public static final int FIRST_OID = 0x1;
	public static final int LAST_OID = 0x7FFFFFFF;
	public static final int FREE_OBJECT_ID_SIZE = LAST_OID - FIRST_OID;

	/**
     *
     *
	 * @return 返回使用的ID--->数组
	 * @throws Exception
	 * @throws java.sql.SQLException
	 */
	protected final List<Integer> extractUsedObjectIDTable() throws Exception{
//		    Connection con = ConnectionFactory.getConnectionFactory().getConnection();
			PreparedStatement statement = null;
			ResultSet rset = null;

            final List<Integer> temp = new ArrayList<Integer>();


//            statement = con.prepareStatement("SELECT uid FROM game_account");
            rset = statement.executeQuery();
			while (rset.next())
			{
				temp.add(rset.getInt(1));
			}
			rset.close();
            Collections.sort(temp);
            return temp;

	}
	
	public boolean isInitialized()
	{
		return _initialized;
	}
	

	public abstract int getNextId();
	
	/**
	 * return a used Object ID back to the pool
	 * @param id
	 */
	public abstract void releaseId(int id);
	
	public abstract int size();



}
